define(function () {
    'use strict';

    function ctrl($scope, $filter, InfoService,$stateParams,CommonService) {
        $scope.term = {};
        var funds = $scope.funds = new Array();
        var par = $scope.param = new Array();
        $scope.$on('$ionicView.beforeEnter', function() {
            par.theme_mark=$stateParams['id'];
            init();
        });

        $scope.doRefresh = function() {
            init();
            $scope.$broadcast("scroll.refreshComplete");
        };

        function init() {
            //获取营地基金概况并添加事件
            queryContentBriefs();
        }

        function queryContentBriefs(){
            //0: 栏目ID 1：产品分级 2：留取条数
            var str = ($scope.term.channel).split(',');
            //查询主题信息
            InfoService.getThemeDetail(par.theme_mark).then(function(data){
                if(data&&data.relate_type){
                    //根据主题标示查询产品
                    $scope.funds=new Array();
                    InfoService.getProdByTheme(par.theme_mark,data.relate_type,data.order_rule).then(function(data){
                        if(data){
                            data = bankThemeQus(data);
                            for(var i=0;i<data.length ;i++){
                                var fund = data[i];
                                fund.prod_min_subscribe = $filter('prodMinSubscribe')(CommonService.getMinAmount(fund));
                                $scope.funds.push(fund);
                            }
                        }
                    });
                }
            });
        }

        //银行理财产品追加描述信息
        function bankThemeQus(data){
            data = data.sort((function(a, b){return parseFloat(a.prodDuration) > parseFloat(b.prodDuration) ? -1 : 1;}));
            for (var i=0;i<data.length;i++){
                if(i==0) {
                    data[i].recommend_reason = '存钱买房，要求收益安全、稳健？';
                }else if (i==1){
                    data[i].recommend_reason = '近半年都不需用，追求安全、省心、方便？';
                }else if (i==2){
                    data[i].recommend_reason = '今年市场琢磨不定，想观望一段时间再做定夺？';
                }else if(i==3){
                    data[i].recommend_reason = '年终奖到手，待春节后再做打算？';
                }else if(i==4){
                    data[i].recommend_reason = '闲钱短期不用，或逃离股市暂时避险？';
                }else{
                    data[i].recommend_reason = '';
                }
            }
            data = data.sort((function(a, b){return parseFloat(a.prod_profit_rate) > parseFloat(b.prod_profit_rate) ? -1 : 1;}));
            return data;
        }
    }

    ctrl.$inject = ['$scope','$filter', 'InfoService','$stateParams','CommonService'];
    return ctrl;
});